var child_process = require('child_process');
var mkdirp = require('mkdirp');
var _ = require('lodash');
var fs = require('fs');
var path = require('path');


module.exports = function(opt) {
  var self = _.defaults(require('./global')(), {
    dataDir: '/tmp/geth-new-sync',
    spawn: function() {
      fs.writeFileSync(
        path.join(self.dataDir, 'static-nodes.json'),
        JSON.stringify([opt.enode]));

      return self.process = child_process.spawn('geth', [
        '--datadir', self.dataDir,
        '--nodiscover',
        '--rpc',
        '--rpcport', '8546',
        '--cache', '512',
        '--port', '30304'
      ]);
    }
  });

  mkdirp.sync(self.dataDir);

  return self;
};
